//
//  RNOLMoneyManagerViewController.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/8.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMoneyManagerViewController.h"
#import "RNOLMoneyManagerTitleView.h"
#import "RNOLMoneyManagerSubViewController.h"
#import "RNOLFilterProjectViewController.h"


@interface RNOLMoneyManagerViewController ()<UIScrollViewDelegate>

@property (nonatomic,strong) RNOLMoneyManagerTitleView *navgationBarTitleView ;
@property (nonatomic,strong) UIScrollView *bgScrollView ;

@end

@implementation RNOLMoneyManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KWhiteColor ;
    [self setupNavgationBarUI];
    [self setup];
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [RNOLLoginTool setNavgationBarNeedAnimation:NO];    
}

- (void)setup{
    UIScrollView *bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH , KHIGHT-kTabBarHeight)];
    bgScrollView.pagingEnabled = YES;
    bgScrollView.delegate = self;
    bgScrollView.contentSize = CGSizeMake(KWIDTH*2, bgScrollView.height);
    [self.view addSubview: bgScrollView];
    self.bgScrollView = bgScrollView;
    
    //投资理财
    RNOLMoneyManagerSubViewController *investVC = [[RNOLMoneyManagerSubViewController alloc] init];
    investVC.type = RNOLInvestTypeManagerMoney;
    [self addChildViewController: investVC];
    investVC.view.frame = bgScrollView.bounds;
    [bgScrollView addSubview: investVC.view];
    
    //债权转让
    RNOLMoneyManagerSubViewController *debtVC = [[RNOLMoneyManagerSubViewController alloc] init];
    debtVC.type = RNOLInvestTypeClaimTransfer;
    [self addChildViewController: debtVC];
    debtVC.view.frame = bgScrollView.bounds;
    debtVC.view.x = KWIDTH;
    [bgScrollView addSubview: debtVC.view];
    
}

- (void)setupNavgationBarUI{
    [self addNavRightButtonWithImage:@"rnol_licai_navlist"];
    RNOLMoneyManagerTitleView *titleView  = [[RNOLMoneyManagerTitleView alloc] initWithFrame:CGRectMake(0, 0, 200 , kNavBarHeight - kStatusBarHeight)];
    [self.navigationItem setTitleView: titleView];
    self.navgationBarTitleView = titleView;
    @weakify(self);
    [titleView setIndexActionBlock:^(NSInteger index) {
        @strongify(self);
        NSLog(@"index ---- %ld",index);
        [self.bgScrollView setContentOffset:CGPointMake(KWIDTH*index, 0) animated:YES];
        
    }];
}

#pragma mark- 导航栏右侧按钮事件
- (void)rightBarButtonAction {
//    kAlertShowMessage(@"导航栏右侧按钮");
    RNOLFilterProjectViewController *filterVC = [[RNOLFilterProjectViewController alloc] init];
    WGBCustomPopUpView *popUp  = [[WGBCustomPopUpView alloc] init];
    popUp.animationType = WGBAlertAnimationTypeRight;
    popUp.touchDismiss =  YES;
    UIView *bgView = [[UIView alloc] initWithFrame: [UIScreen mainScreen].bounds];
    bgView.backgroundColor = [UIColor clearColor];
    bgView.userInteractionEnabled = YES;
    filterVC.view.frame = CGRectMake(35, 0, KWIDTH - 35, KHIGHT);
    [bgView addSubview: filterVC.view];
    popUp.contentView = bgView;
    [popUp show];
    [filterVC setResetBlock:^{
        [self showStatusTipWithText:@"重置..,."];
    }];
    [filterVC setConfirmBlock:^{
        [popUp dismiss];
    }];
}

#pragma mark- <UIScrollViewDelegate>
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSInteger offset = (NSInteger)scrollView.contentOffset.x ;
    NSInteger index = (NSInteger)offset/KWIDTH;
    if ((offset % (NSInteger)KWIDTH) == 0) {
        [self.navgationBarTitleView scrollSelectIndex: index];
    }
}




@end
